<script>

  export default {
    data() {
      return {
        chongZhiZhongLei: [
          {
            rmb: 8,
            db: 8,
            zengSong: 2
          }, {
            rmb: 28,
            db: 28,
            zengSong: 5
          }, {
            rmb: 68,
            db: 68,
            zengSong: 10
          }, {
            rmb: 168,
            db: 168,
            zengSong: 48
          }, {
            rmb: 288,
            db: 288,
            zengSong: 68
          }, {
            rmb: 8,
            db: 8,
            zengSong: 2
          }, {
            rmb: 8,
            db: 8,
            zengSong: 2
          }, {
            rmb: 388,
            db: 388,
            zengSong: 100
          }
        ]
      }
    },
    computed: {
      windowHeight() {
        return this.$store.state.windowHeight
      }
    },
    mounted() {
      this.ajaxCZList();
      //检测地址参数是否有recharge
      let urlP=new UrlSearch();
      console.log(urlP);
      let recharge=urlP.recharge;
      if(recharge){
        recharge =parseFloat(recharge);
        if(recharge){

        }
      }
    },
    methods: {
      ajaxCZList() {
        ajaxCore.ajax(config.szg.discountInfo, null, "POST", {
          "Authorization": getToken()
        }).done((res) => {
          if (res.status == 10001) {
            let chongZhiZhongLei = [];
            //麻痹徐翔不把金额排序
            if (res.result.length > 2) {
              if (res.result[0].price > res.result[1].price) {
                res.result = res.result.reverse();
              }
            }
            for (let i = 0; i < res.result.length; i++) {
              chongZhiZhongLei.push({
                rmb: res.result[i].price,
                db: res.result[i].price,
                zengSong: res.result[i].free,
              })
            }
            this.chongZhiZhongLei = chongZhiZhongLei;
          }
        })
      },
      chongZhi(item) {
//        layer.msg('功能马上开放。。。')
        let _self = this;
        var _config = {
          amount: item.rmb * 100,
          "openId": config.jc.info.openid(),
          number: 0
        };
        if (_config.amount == 0) {
          layer.alert("请输入金额");
        } else {
          ajaxCore.ajax(config.szg.recharge, _config, "get", {
            "Authorization": getToken()
          }).done(function (data) {
            console.log(JSON.stringify(data));
            if (data.status == 10001) {
              var res = data.result;
              WeixinJSBridge.invoke(
                'getBrandWCPayRequest', {
                  "appId": res.appid,     //公众号名称，由商户传入
                  "paySign": res.sign,         //微信签名
                  "timeStamp": res.timeStamp, //时间戳，自1970年以来的秒数
                  "nonceStr": res.nonce_str, //随机串
                  "package": res.packageStr,  //预支付交易会话标识
                  "signType": res.signType     //微信签名方式
                },
                function (res) {
//                            alert(JSON.stringify(res));//出错可以在这里看看.....
                  if (res.err_msg == "get_brand_wcpay_request:ok") {
                    layer.msg('支付成功');
                  } else if (res.err_msg == "get_brand_wcpay_request:cancel") {
                    layer.msg('支付取消');
                  } else if (res.err_msg == "get_brand_wcpay_request:fail") {
                    layer.msg('支付失败');
                  }
                  //使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
                }
              );
            } else if (data.status == 10004) {
//              window.location.href = config.szg.start;
            } else {
            }
          });
        }
      },
      //用共用方法充值
      chongZhi2(item){
        DYD.whatToDoByType(2,{
          amount: item.rmb * 100,
          number: 0
        })
      },
      goBack() {
        this.$router.push('/plain')
      }
    }
  }
</script>
<template>
  <div class="szg_plainScore szg_chongZhi ">
    <div class="szg_chongZhi_head">
      <img @click="goBack" src="../../../../static/staticJC/images/event/back.png" alt="返回" class="szg_chongZhi_back">
      <div class="szg_chongZhi_cz_btn"><span></span></div>
    </div>
    <div class="szg_chongZhi_content" :style="{height:windowHeight-60+'px',overflow:'auto'}">
      <ul>
        <li class="szg_chongZhi_cons" v-for="(item,index) in chongZhiZhongLei">
          <div class="szg_chongZhi_cons_bg">
            <p class="szg_chongZhi_slo1">{{item.db}}都币</p>
            <p class="szg_chongZhi_slo4">赠送{{item.zengSong}}都币</p>
            <p class="szg_chongZhi_slo2">1元=1都币</p>
            <div class="szg_chongZhi_slo3" @click="chongZhi2(item)">
              <span>{{item.rmb}}元</span></div>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>
<style scoped>
  html, body {
    height: 100%;
  }

  #app {
    height: 100%;
  }
</style>
